import userService from "./userService.js";
import validator from "../../../utils/validator.js";
const userController = {
  async addUser(ctx, next) {
    let {username, password, roleId} = ctx.request.body;
    ctx.body = await userService.addUser(username, password, roleId)
  },

  async delUser(ctx, next) {
    let {id} = ctx.request.body;
    ctx.body = await userService.delUser(id);
  },

  async getUser(ctx, next) {
    let {username, password} = ctx.request.body;
    ctx.body = await userService.getUser(username);
  },

  async getUserByOrg(ctx, next) {
    let {username, password} = ctx.request.body;
    let isValid = await validator(ctx, next, {
      username: {type: 'string', required: true},
      password: {type: 'string', required: true},
    });
    if (isValid !== true) return
    ctx.body = await userService.getUserByOrg(username);
  },
  async updateUserById(ctx, next) {
    let {username} = ctx.request.body;
    ctx.body = await userService.updateUserById(username);
  },
  async getUserAndRoleName(ctx, next) {
    let {username} = ctx.request.body;
    ctx.body = await userService.getUserAndRoleName(username);
  }

}
export default userController;